

/**
	setTimeout class,
	@author  Ashley Holtgraver
	@version 2005-11-17

	@usage
	<code>
	var delayfunc = new SetTimeout(myFunction, 500);
	var delayfunc2 = new SetTimeout(myFunction, 500, myscope);
	var delayfunc3 = new SetTimeout(myFunction, 500, myscope, myarg, myarg2);
	</code>


	@notes
	Scope and arguments are optional, to be used in the same way as the second syntax of setInterval.
	The simplest usage is to emply mx.utils.Delegate() to make a delegate for the function argument
	since the scope arg in setInterval is a bit buggy.


*/

import mx.utils.Delegate;

dynamic class timber.util.SetTimeout
{	
 	private var interval:Number;
	private var f:Function;
	private var scope:Object;
	
	/*
	* @param f:Function : The function you want to call
	* @param delay:Number : The number of milliseconds delay
	* @param scope:Object : The object in which the function should be scoped
	**/
	public function SetTimeout(f:Function, delay:Number, scope:Object){
  		this.f = f; 
		this.scope = scope;
		this.args = arguments.slice(3);
		trace(">>> " + f + " :: " + delay + " :: " + scope);
		trace(">>>> >>> " + this + " :: " + trigger + " :: " + delay);
		interval = setInterval(Delegate.create(this, trigger), delay);
	}

	private function trigger(Void):Void{
  		clearInterval(interval);
  		f.apply(scope, this.args);
	}

}
